#include"thread.h"

/*typedef struct dirNode_s{
    char dirName[256];
    struct dirNode_s *pNext;
}dirNode_t;

typedef struct dirQueue_s{
    dirNode_t *pFornt;
    dirNode_t *pRear;
    int size;
}dirQueue_t;

typedef struct dirID_s{
    dirQueue_t userID;
    char pwdID[256];
}dirID_t;*/

int mkDir(dirID_t* dirID, int netfd) {
    train_t train;
    recv(netfd,&train.length,sizeof(int),MSG_WAITALL);
    recv(netfd,train.buf,train.length,MSG_WAITALL);
    
    char strID[256];
    get_user_dir(strID,dirID);
    
    char tmp[2048];
    strcpy(tmp,dirID->pwdID);
    strcat(tmp,strID);
    strcat(tmp,"/");
    strcat(tmp,train.buf);
    char prossedBuf[256];
    removeHiddenCharacters(train.buf,prossedBuf);
    printf("mkdir_tmp = %s\n",prossedBuf);

    int ret=mkdir(tmp, 0777);//创建目录
    ERROR_CHECK(ret,-1,"mkdir");

   /* int orderLen = strlen(dirID->pwdID);
    int count = 0;
    for (int i = 1; i < orderLen; i++) {//统计pwd中'/'的数量
        if (dirID->pwdID[i] == '/') {
            count++;
        }
    }
    if (count >= 1) {//路径层级大于等于1，
        puts("too much fir");
        return -1;
    }
*/
    
/**  //检查命令是否以'/'开头
    if (train.buf[0] == '/') {
        if (strcmp(train.buf, "/..") == 0 || strcmp(train.buf, "/.") == 0) {//分析传来的命令头部带不带‘、’，以及禁止建立“/..”和“/.”文件夹
            puts("can't make this");
            return -1;
        }
        strcat(tmp, train.buf);
    } else {
        if (strcmp(train.buf, "..") == 0 || strcmp(train.buf, ".") == 0) {
            puts("can't make this");
            return -1;
        }
        strcat(tmp, "/");
        strcat(tmp, train.buf);
    }

    DIR* checkdir = opendir(tmp);
    if (checkdir != NULL) {
        puts("the dir is already build");//目录已经创建
        return -1;
    } else {
        mkdir(tmp, 0775);//创建目录
    }*/

    return 0;
}
